package com.cnbm.wcsbasic.protocol.netty.modbus.moban;


import com.cnbm.wcsbasic.protocol.netty.io.FGClient;

import java.util.ArrayList;
import java.util.List;

/**
 * @Desc: ""
 * @Author: caixiang
 * @DATE: 2024-04-15 14:04
 */
public class ReadTest {
    public static void main(String[] args) throws InterruptedException {

        {
            //BOOL AND ARRAY READ/WRITE
            System.err.println("write1Bool: " + FGClient.local.write(DevPlcVar.bool, true));
            //注意如果 address:26 这个变量长度是8，那么每次write 长度也要8；
            System.err.println("writeBoolArray: " + FGClient.local.write(DevPlcVar.boolArray, new boolean[]{true,true,false,true,false,true,false,true}));
            System.err.println("read1Bool: " + FGClient.local.read(DevPlcVar.bool));
            System.err.println("readBoolArray: " + FGClient.local.read(DevPlcVar.boolArray));
        }


//        {
//            //BYTE AND ARRAY READ/WRITE
//            System.err.println("readByteArray: " + FGClient.local.read(DevPlcVar.byteArray));
//            System.err.println("read1Byte: " + FGClient.local.read(DevPlcVar.bytevar));
//            //注意如果 address:11 这个变量长度是4，那么每次write 长度也要4
//            System.err.println("writeByteArray: " + FGClient.local.write(DevPlcVar.byteArray, new byte[]{(byte)16,(byte)16,(byte)16,(byte)16}));
//            System.err.println("write1Byte: " + FGClient.local.write(DevPlcVar.bytevar, (byte)0x13));
//        }

//        {
//            //INT AND ARRAY READ/WRITE
//            System.err.println("readIntArray 1: " + FGClient.local.read(DevPlcVar.intvar));
//            System.err.println("read1Int 1: " + FGClient.local.read(DevPlcVar.intArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要4
//            System.err.println("writeIntArray: " + FGClient.local.write(DevPlcVar.intArray, new int[]{20,20,20,20,20,20,20,20,20}));
//            System.err.println("write1Int: " + FGClient.local.write(DevPlcVar.intvar, 22));
//            System.err.println("readIntArray 2: " + FGClient.local.read(DevPlcVar.intArray));
//            System.err.println("read1Int 2: " + FGClient.local.read(DevPlcVar.intvar));
//        }


//        {
//            //SINT AND ARRAY READ/WRITE
//            System.err.println("read1SInt 1: " + FGClient.local.read(DevPlcVar.sintvar));
//            System.err.println("readSIntArray 1: " + FGClient.local.read(DevPlcVar.sintArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要4
//            System.err.println("write1SInt: " + FGClient.local.write(DevPlcVar.sintvar, 23));
//            System.err.println("writeSIntArray: " + FGClient.local.write(DevPlcVar.sintArray, new int[]{21,20,21,20,21,20,21,20,21,20,20,20,20,20}));
//
//            System.err.println("read1SInt 2: " + FGClient.local.read(DevPlcVar.sintvar));
//            System.err.println("readSIntArray 2: " + FGClient.local.read(DevPlcVar.sintArray));
//        }

//        {
//            //USINT AND ARRAY READ/WRITE
//            System.err.println("read1USInt 1: " + FGClient.local.read(DevPlcVar.usintvar));
//            System.err.println("readUSIntArray 1: " + FGClient.local.read(DevPlcVar.usintArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要4
//            System.err.println("write1USInt: " + FGClient.local.write(DevPlcVar.usintvar, 23));
//            System.err.println("writeUSIntArray: " + FGClient.local.write(DevPlcVar.usintArray, new int[]{21,20,21,20,21,20,21,20,21,20,20,20,20,20}));
//
//            System.err.println("read1USInt 2: " + FGClient.local.read(DevPlcVar.usintvar));
//            System.err.println("readUSIntArray 2: " + FGClient.local.read(DevPlcVar.usintArray));
//        }
//
//        {
//            //USINT AND ARRAY READ/WRITE
//            System.err.println("read1DInt 1: " + FGClient.local.read(DevPlcVar.dintvar));
//            System.err.println("readDIntArray 1: " + FGClient.local.read(DevPlcVar.dintArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要4
//            System.err.println("write1DInt: " + FGClient.local.write(DevPlcVar.dintvar, 23));
//            System.err.println("writeDIntArray: " + FGClient.local.write(DevPlcVar.dintArray, new int[]{21,20}));
//
//            System.err.println("read1DInt 2: " + FGClient.local.read(DevPlcVar.dintvar));
//            System.err.println("readDIntArray 2: " + FGClient.local.read(DevPlcVar.dintArray));
//        }
//
//        {
//            //LINT AND ARRAY READ/WRITE
//            System.err.println("read1LInt 1: " + FGClient.local.read(DevPlcVar.lintvar));
//            System.err.println("readLIntArray 1: " + FGClient.local.read(DevPlcVar.lintArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41
//            List<Long> objects = new ArrayList<>();
//            objects.add(10L);
//            objects.add(25543L);
//            System.err.println("write1LInt: " + FGClient.local.write(DevPlcVar.lintvar, 23));
//            System.err.println("writeLIntArray: " + FGClient.local.write(DevPlcVar.lintArray, objects));
//            System.err.println("read1LInt 2: " + FGClient.local.read(DevPlcVar.lintvar));
//            System.err.println("readLIntArray 2: " + FGClient.local.read(DevPlcVar.lintArray));
//        }

//        {
//            //String AND ARRAY READ/WRITE
//            System.err.println("read1String 1: " + FGClient.local.read(DevPlcVar.stringvar));
//            System.err.println("read1StringArray 1: " + FGClient.local.read(DevPlcVar.stringArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41
//
//            String[] objects = new String[4];
//            objects[0] ="dsadjqwio";
//            objects[1] ="caixiangcaixiang";
//            objects[2] ="";
//            objects[3] ="CAIXIANGCAIXIANGG";
//
//            StringArrayStruc stringArrayStruc = new StringArrayStruc(objects, 16);
//            System.err.println("write1String: " + FGClient.local.write(DevPlcVar.stringvar, "8ABC10088ABC1008aa"));
//            System.err.println("writeStringArray: " + FGClient.local.write(DevPlcVar.stringArray, stringArrayStruc));
//
//            System.err.println("read1String 2: " + FGClient.local.read(DevPlcVar.stringvar));
//            System.err.println("read1StringArray 2: " + FGClient.local.read(DevPlcVar.stringArray));
//        }

//        {
//            //Real AND ARRAY READ/WRITE
//            System.err.println("read1Real 1: " + FGClient.local.read(DevPlcVar.realvar));
//            System.err.println("read1RealArray 1: " + FGClient.local.read(DevPlcVar.realArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41
//
//            //注意，这里floatList.size() 不要超过 plc 上定义的长度，负责内容会写到 其他区域上去。
//            List<Float> floatList = new ArrayList<>();
//            floatList.add(156.1001f);
//            floatList.add(1f);
//            floatList.add(156.3f);
//            floatList.add(156.4f);
//            floatList.add(156.5f);
//            floatList.add(156.6f);
//            floatList.add(156.7f);
//            floatList.add(156.8f);
//            floatList.add(156.9f);
//            floatList.add(156.11f);
//
//            System.err.println("write1Real: " + FGClient.local.write(DevPlcVar.realvar, Float.valueOf("566.111")));
//            System.err.println("writeRealArray: " + FGClient.local.write(DevPlcVar.realArray, floatList));
//
//            System.err.println("read1Real 2: " + FGClient.local.read(DevPlcVar.realvar));
//            System.err.println("read1RealArray 2: " + FGClient.local.read(DevPlcVar.realArray));
//        }


        {
            //Lreal AND ARRAY READ/WRITE
            System.err.println("read1LReal 1: " + FGClient.local.read(DevPlcVar.lrealvar));
            System.err.println("read1LRealArray 1: " + FGClient.local.read(DevPlcVar.lrealArray));
            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41

            //注意，这里floatList.size() 不要超过 plc 上定义的长度，负责内容会写到 其他区域上去。
            List<Double> doubles = new ArrayList<>();
            doubles.add(111.1001d);
            doubles.add(157.2d);
            doubles.add(157.3d);
            doubles.add(157.4d);
            doubles.add(157.5d);
            doubles.add(157.6d);
            doubles.add(157.7d);
            doubles.add(157.8d);
            doubles.add(157.9d);
            doubles.add(111.11d);

            System.err.println("write1LReal: " + FGClient.local.write(DevPlcVar.lrealvar, Float.valueOf("111.111")));
            System.err.println("writeLRealArray: " + FGClient.local.write(DevPlcVar.lrealArray, doubles));

            System.err.println("read1LReal 2: " + FGClient.local.read(DevPlcVar.lrealvar));
            System.err.println("read1LRealArray 2: " + FGClient.local.read(DevPlcVar.lrealArray));
        }



//        {
//            //WORD AND ARRAY READ/WRITE
//            System.err.println("read1Word 1: " + FGClient.local.read( DevPlcVar.wordvar ));
//            System.err.println("readLWordArray 1: " + FGClient.local.read( DevPlcVar.wordArray ));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41
//            short[] shorts = new short[9];
//            shorts[0] = -2;
//            shorts[1] = 1;
//            shorts[2] = 0;
//            shorts[3] = 999;
//            shorts[4] = -876;
//            shorts[5] = 1;
//            shorts[6] = 1;
//            shorts[7] = 1;
//            shorts[8] = 1;
//
//            System.err.println("write1Word: " + FGClient.local.write(DevPlcVar.wordvar, 23));
//            System.err.println("writeWordArray: " + FGClient.local.write(DevPlcVar.wordArray, shorts));
//            System.err.println("read1Word 2: " + FGClient.local.read(DevPlcVar.wordvar));
//            System.err.println("readWordArray 2: " + FGClient.local.read(DevPlcVar.wordArray));
//        }

//        {
//            //DWORD AND ARRAY READ/WRITE
//            System.err.println("read1DWord 1: " + FGClient.local.read(DevPlcVar.dwordvar));
//            System.err.println("readDWordArray 1: " + FGClient.local.read(DevPlcVar.dwordArray));
//            ////注意如果 address:11 这个变量长度是4，那么每次write 长度也要41
//            int[] ints = new int[9];
//            ints[0] = -2;
//            ints[1] = 1;
//            ints[2] = 0;
//            ints[3] = 999;
//            ints[4] = -876;
//            ints[5] = 1;
//            ints[6] = 1;
//            ints[7] = 1;
//            ints[8] = -998;
//
//            System.err.println("write1DWord: " + FGClient.local.write(DevPlcVar.dwordvar, 99));
//            System.err.println("writeDWordArray: " + FGClient.local.write(DevPlcVar.dwordArray, ints));
//            System.err.println("read1DWord 2: " + FGClient.local.read(DevPlcVar.dwordvar));
//            System.err.println("readDWordArray 2: " + FGClient.local.read(DevPlcVar.dwordArray));
//        }

        //todo 写bool的时候可能写 错位了，写到 后面那个单元了
        //todo 测试 byteArray 和  boolArray  满载 和 非满载情况。
    }
}